Skip to content

feat: add AllocEvent and FreeEvent to trace format#420

Merged
rcoh merged 1 commit into
mainfrom
feat/alloc-free-events
May 18, 2026
Merged

feat: add AllocEvent and FreeEvent to trace format#420
rcoh merged 1 commit into
mainfrom
feat/alloc-free-events

Conversation

@rcoh
Copy link
Copy Markdown
Contributor

@rcoh rcoh commented May 18, 2026

Adds wire-format definitions for sampled allocation and matching free events that the upcoming memory profiler will emit. Per design §3:

  • AllocEvent { timestamp_ns, tid, size, addr, callchain }
  • FreeEvent { timestamp_ns, tid, addr, size, alloc_timestamp_ns }

size and alloc_timestamp_ns are denormalized onto FreeEvent so leak analysis stays useful when the matching AllocEvent has been evicted by trace rotation.

This is the schema only — no producer (allocator hook) and no UI flamegraph yet. Both will land in follow-up PRs (ring-buffer scaffold, Dial9Allocator wrapper, MemoryProfiler::install, hook wiring) per the rollout in design §15.

API shape

Both events are gated on #[cfg_attr(not(feature = "unstable-events"), non_exhaustive)]. By default (no feature) they cannot be constructed by downstream crates, so adding fields later is non-breaking. Crates that need to construct them directly (e.g. for tests or custom event injection) opt in to unstable-events and accept that new fields may break them.

Backwards compatibility

Per AGENTS.md trace-format rules: this PR only adds new event types. Old traces don't contain AllocEvent / FreeEvent, the JS decoder gracefully no-ops on missing schemas, and we don't need old Rust decoders to read new traces.

Demo trace

Not regenerated — there is no producer of these events yet.

Verification

  • cargo fmt --check: clean
  • cargo clippy --all-targets --all-features: clean
  • cargo nextest run: 594/594 passed
  • cargo nextest run --stress-duration 20s: 2 iterations × 594/594 passed

Adds wire-format definitions for sampled allocation and matching free
events
that the upcoming memory profiler will emit. Per design §3:
- AllocEvent { timestamp_ns, tid, size, addr, callchain }
- FreeEvent { timestamp_ns, tid, addr, size, alloc_timestamp_ns }

`size` and `alloc_timestamp_ns` are denormalized onto FreeEvent so leak
analysis stays useful when the matching AllocEvent has been evicted by
trace
rotation.

This is the schema only — no producer (allocator hook) and no UI
flamegraph
yet. Both will land in later commits per the rollout in design §15.

Demo trace not regenerated: there is no producer of these events yet.
@rcoh rcoh force-pushed the feat/alloc-free-events branch from c791bfc to 90b35b2 Compare May 18, 2026 16:08
@rcoh rcoh requested a review from a team May 18, 2026 17:56
Copy link
Copy Markdown
Collaborator

@yulnr yulnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Side note: I wonder if we eventually want to make TelemetryEvent #[non_exhaustive]. Though I guess often new additions here mean breaking changes either way, and perhaps for the analysis tool you would like to be aware of new events rather than skip them.

@rcoh
Copy link
Copy Markdown
Contributor Author

rcoh commented May 18, 2026

yeah we definitely want to make that #[non_exhaustive]. What we actually want is a TelemetryEvent that is much more like how we parse it in JS where its open ended and based only on field names

@rcoh rcoh added this pull request to the merge queue May 18, 2026
Merged via the queue into main with commit 3c8e41a May 18, 2026
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants